﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
    [TestClass]
    public class UserData_55_SupportedUserDataTypes_Test
    {
        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test01_Equals_Null()
        {
            UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x77, null);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different derived type 
                ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
                UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // same object - equal
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, userData.SupportedUserDataTypes);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes((byte) (userData.Device + 1), userData.SupportedUserDataTypes);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different supported types
				SortedSet<byte> supTypes = new SortedSet<byte>{ 0x44 };
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, supTypes);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test02_Equals_Empty()
        {
			SortedSet<byte> supTypes = new SortedSet<byte>();
            UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x77, supTypes);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different derived type 
                ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
                UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // same object - equal
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, userData.SupportedUserDataTypes);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes((byte)(userData.Device + 1), userData.SupportedUserDataTypes);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different supported types
				SortedSet<byte> supTypes2Compare = new SortedSet<byte> { 0x01, 0x02, 0x03 };
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, supTypes2Compare);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test03_Equals_OneItem()
        {
			SortedSet<byte> supTypes = new SortedSet<byte> { 0x01 };
            UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x77, supTypes);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different derived type 
                ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
                UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // same object - equal
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, userData.SupportedUserDataTypes);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes((byte)(userData.Device + 1), userData.SupportedUserDataTypes);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different supported types
                SortedSet<byte> supTypes2Compare = new SortedSet<byte> { 0x01, 0x02, 0x03 };
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, supTypes2Compare);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test04_Equals_MultipleItems()
        {
			SortedSet<byte> supTypes = new SortedSet<byte> { 0x03, 0x01, 0x02, };
            UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x77, supTypes);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different derived type 
                ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
                UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // same object - equal
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, userData.SupportedUserDataTypes);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different device
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes((byte)(userData.Device + 1), userData.SupportedUserDataTypes);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different supported types
				SortedSet<byte> supTypes2Compare = new SortedSet<byte> { (byte)(supTypes.ElementAt(0) + 1), supTypes.ElementAt(1), supTypes.ElementAt(2) };
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, supTypes2Compare);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different supported types
				SortedSet<byte> supTypes2Compare = new SortedSet<byte> { supTypes.ElementAt(0), (byte)(supTypes.ElementAt(1) + 1), supTypes.ElementAt(2) };
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, supTypes2Compare);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different supported types
				SortedSet<byte> supTypes2Compare = new SortedSet<byte> { supTypes.ElementAt(0), supTypes.ElementAt(1), (byte)(supTypes.ElementAt(2) + 1) };
                UserData_55_SupportedUserDataTypes userData2Compare = new UserData_55_SupportedUserDataTypes(userData.Device, supTypes2Compare);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test05_GetHashCode()
        {
            {
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x77, null);
                int hashCode = userData.GetHashCode();
            }

            {
            	SortedSet<byte> supTypes = new SortedSet<byte>();
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x78, supTypes);
                int hashCode = userData.GetHashCode();
            }

            {
				SortedSet<byte> supTypes = new SortedSet<byte> { 0x01 };
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x79, supTypes);
                int hashCode = userData.GetHashCode();
            }

            {
				SortedSet<byte> supTypes = new SortedSet<byte> { 0x01, 0x02, 0x03 };
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x7A, supTypes);
                int hashCode = userData.GetHashCode();
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test06_ToString()
        {
            {
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x77, null);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }

            {
            	SortedSet<byte> supTypes = new SortedSet<byte>();
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x78, supTypes);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }

            {
				SortedSet<byte> supTypes = new SortedSet<byte> { 0x01 };
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x79, supTypes);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }

            {
				SortedSet<byte> supTypes = new SortedSet<byte> { 0x01, 0x02, 0x03, 0xef };
                UserData_55_SupportedUserDataTypes userData = new UserData_55_SupportedUserDataTypes(0x7A, supTypes);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }
        }
    }
}
